<?php

namespace App\Admin\Controllers;


class CommonController extends BaseController
{
    public function sort(){
        $ids=request('id');
        $model=urldecode(request('model'));
        $idStr = implode(',', $ids);
        $sortData = $model::whereIn('id', $ids)
            ->orderByRaw("find_in_set(id,'{$idStr}')")->get();
        $sorts = array_column($sortData->toArray(), 'sort');
        rsort($sorts);
        foreach ($ids as $key => $id) {
            $model::whereId($id)->update(['sort' => $sorts[$key]]);
        }
    }
}
